import axios from 'axios';
import { commonParams, ERR_OK } from '@/common/js/config';

export function getHotKey() {
  const url = '/api/hotkey';
  const data = Object.assign({}, commonParams, {
    format: 'json',
    uin: 0,
    needNewCode: 1,
    platform: 'h5',
  });
  return axios.get(url, {
    params: data,
  }).then((res) => {
    // express res
    if (res.data.code === ERR_OK) {
      return Promise.resolve(res.data.data);
    }
    return 'error';
  }).catch(err => console.error(err));
}

export function getSearchList({ w, page, zhida, perpage }) {
  const url = '/api/getSearchList';
  const data = Object.assign({}, commonParams, {
    w,
    p: page,
    perpage,
    n: perpage,
    catZhida: zhida ? 1 : 0,
    format: 'json',
    zhidaqu: 1,
    t: 0,
    flag: 1,
    ie: 'utf-8',
    sem: 1,
    aggr: 0,
    remoteplace: 'txt.mqq.all',
    uin: 0,
    needNewCode: 1,
    platform: 'h5',
  });
  return axios.get(url, {
    params: data,
  }).then((res) => {
    // express res
    if (res.data.code === ERR_OK) {
      return Promise.resolve(res.data.data);
    }
    return 'error';
  }).catch(err => console.error(err));
}
